<?php

/**
* 货品表管理模型
*/
class GoodsListModel extends Model{
    public $table='goods_list';
    
    public $validate=array(
    	array('inventory','nonull','未填写库存',2,3),
        array('combine','isEmpty','未选择规格的值',2,3)
    );
    
    /*验证规格是否全部填写	
     **/
    public function isEmpty($name, $value, $msg, $arg){
    	foreach ($value as $v) {
    		if($v=='0'){
    			return $msg;
    		}
    	}
		return true;
    }
	
    /*添加货品
     **/
    public function addGoodsList(){
    	$goodsGid=Q('get.gid',0,'intval');
		if(!$this->create()) return false;
		$this->data['combine']=implode(',',$_POST['combine']);
		$this->data['goods_gid']=$goodsGid;
        $this->add();
		M('goods')->inc('store',"gid={$goodsGid}",Q('post.inventory',0,'intval'));
		return true;
    }
	
	
	/*修改货品
	 **/
	public function editGoodsList(){
	    $goodsGid=Q('post.goodsGid',0,'intval');
		if(!$this->create()) return false;
		$this->data['combine']=implode(',',$_POST['combine']);
		$this->data['goods_gid']=$goodsGid;
		$this->update();
		$diff=Q('post.inventory',0,'intval')-Q('post.oldInventory',0,'intval');
		M('goods')->inc('store',"gid={$goodsGid}",$diff);
	}
	
	
	

}
    
    
    
?>